import threading
import win32gui
from pk.WindowManager import WindowManager


# 选择窗口
class MoveWin:
    def __init__(self, setupui):
        self.setupUi = setupui
        self.threads = []  # 用于存储所有挖图线程
        self.stop_flag = threading.Event()

    def btn_command(self):
        if self.setupUi.selectHwnd:
            # 窗口大小
            width, height = 640, 512
            # 起始位置
            start_left, start_top = 0, 0
            # 每行最多显示3个窗口
            max_per_row = 3
            for idx, hwnd in enumerate(self.setupUi.selectHwnd):
                row = idx // max_per_row
                col = idx % max_per_row
                left = start_left + col * width
                top = start_top + row * height
                self.setupUi.add_log("调整句柄"+ hwnd)
                thread = threading.Thread(target=WindowManager.set_window_size, args=(hwnd, left, top, width, height))
                thread.daemon = True
                thread.start()
        else:
            self.setupUi.add_log("未选择窗口，无法调整界面")
            return
